﻿@using Newtouch.Infrastructure;
@{
    ViewBag.Title = "队列查询";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style>

    #dv_pretb {
        font-size: 14px;
        border: 2px solid rgba(26, 157, 251, 0.80);
        border-radius:5px;
        background-color: azure;
    }
    #pretb th {
        padding: 5px 10px;
        border-right: 2px solid rgb(111, 216, 171);
    }
        #pretb td {
            padding:3px 5px;
            
        }
  
</style>
<div class="topPanel">
    <div class="search">
        <table class="form">
            <tr>
                <td colspan="3">
                    <div id="time_horizon" class="btn-group" style="float:left;margin-top:10px;">
                        <a class="btn btn-default active" data-value="1">今天</a>
                        <a class="btn btn-default" data-value="2">历史叫号</a>
                    </div>
                    <input id="txt_jhrq" type="text" class="form-control input-wdatepicker" style="height:12px;margin-top:10px;width:30%;float:left;"
                           onclick="WdatePicker({ dateFmt: 'yyyy-MM-dd' })"
                           onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd',maxDate: new Date().format('yyyy-MM-dd')})" value="@DateTime.Now.ToString("yyyy-MM-dd ")" />
                </td>
                <td class="formTitle">队列类型</td>
                <td class="formValue">
                    <select id="ywbz" style="width:50%;" data-enumType="Enummzzybz"></select>
                </td>
                <td class="formTitle">号源类型</td>
                <td class="formValue">
                    <select id="ywlx" data-enumType="EnumOutPatientType">
                        <option value="">全部</option>
                    </select>
                </td>
                @*<td class="formTitle">科室</td>*@
                <td class="formValue">
                    <input type="text" id="ks" class="form-control" />
                    <input type="text" id="ksCode" class="form-control" style="display:none;"/>
                </td>
                <td></td>
                <td colspan="2">
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="姓名/卡号" style="width: 100px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>


            </tr>
        </table>
    </div>
</div>
<div id="dv_pretb" style="width:98%;text-align:center;height:100px;">
    <table id="pretb" style="border-right:2.5px solid rgb(111, 216, 171);">
        <tr id="tr_calling">           
            <th rowspan="3">普<br />通<br />队<br />列</th>
            <td>
                <span style="color:red;">当前叫号：</span> <span id="sp_calling_no" style="font-weight:bold;color:red;text-decoration:underline;">1</span>
            </td>
            <td>
                <span id="sp_calling_xm">张三</span>
            </td>
            <td>
                <span id="sp_calling_dept">消化内科门诊</span>
            </td>
            <td>
                <span id="sp_calling_doc">熊甜甜 </span>
            </td>
            <td>
                <span id="sp_calling_ywlx" style="color:#ff6a00;">【专家】</span>
            </td>
        </tr>
        <tr id="tr_nextcall">
            <td>
                <span>接续待叫：</span><span id="sp_nextcall_no">2</span>
            </td>
            <td>
                <span id="sp_nextcall_xm">李四</span>
            </td>
            <td>
                <span id="sp_nextcall_dept">消化内科门诊</span>
            </td>
            <td>
                <span id="sp_nextcall_doc">熊甜甜 </span>
            </td>
            <td>
                <span id="sp_nextcall_ywlx" style="color:#ff6a00;">【专家】</span>
            </td>
        </tr>
        <tr>
            <td>等待人数：<span id="sp_waiting_count">0 </span></td>
            <td></td>
            <td></td>
        </tr>
    </table>
</div>
<div style="width:40%;float:left;">
    <div class="gridPanel">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
</div>
<div style="width:58%;float:right;">
    <div style="padding:5px 20px;height:20px;float:right;">
        <div id="called_horizon" class="btn-group" style="z-index:1;">
            @*<a class="btn btn-default active" id="btn_call" data-value="@((int)EmunQueueCalledStu.call)" onclick="gridListcalledChange('@((int)EmunQueueCalledStu.call)')">已叫队列</a>
        <a class="btn btn-default" id="btn_pass" data-value="@((int)EmunQueueCalledStu.pass)" onclick="gridListcalledChange('@((int)EmunQueueCalledStu.pass)')">过号队列</a>
        <a class="btn btn-default" id="btn_reply" data-value="@((int)EmunQueueCalledStu.reply)" onclick="gridListcalledChange('@((int)EmunQueueCalledStu.reply)')">到诊队列</a>*@
            <a class="btn btn-default active" id="btn_call" data-value="@((int)EmunQueueCalledStu.call)" >已叫队列</a>
            <a class="btn btn-default " id="btn_pass" data-value="@((int)EmunQueueCalledStu.pass)" >过号队列</a>
            <a class="btn btn-default" id="btn_reply" data-value="@((int)EmunQueueCalledStu.reply)" >到诊队列</a>
        </div>
        <hr />
    </div>
    <div class="gridPanel">
        <table id="calledgridList"></table>
        <div id="calledgridPager"></div>
    </div>
</div>


<script>
    $(function () {
        initControl();
        gridList();
        gridListcalled();
        getNextCall();
    })

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/QueueManage/QueueInfo/GetQueueInfo",
            height: $(window).height() - 258,
            postData: { keyword: $("#txt_keyword").val(), qdsj: new Date().format('yyyy-MM-dd'), calledstu: '@((int)EmunQueueCalledStu.sign)'},
            colModel: [
                {
                    label: '操作区', name: 'action', width: 80, align: 'center', frozen: true, formatter: function (cellvalue, op, row) {
                        if ($("#time_horizon a.active").attr('data-value') != 1) {
                            return '';
                        } else {
                            return '<input type="button" class="btn btn-default"  onclick="jiaohao(' + row.ywlsh + ',' + @Html.Raw(((int)EmunQueueCalledStu.call).ToString()) + ')" value="叫号" /> <input type="button" class="btn btn-default"  onclick="jiaohao(' + row.ywlsh + ',' + @Html.Raw(((int)EmunQueueCalledStu.pass).ToString()) + ')" value="过号" />';
                        }
                    },
                },
                { label: '序号', name: 'queno', width: 30, align: 'center', frozen: true },
                { label: '姓名', name: 'xm', width: 80, align: 'left', frozen: true },
                { label: '主键', name: 'Id', hidden: true },
                { label: 'ywbz', name: 'ywbz', hidden: true },
                {
                    label: '号源类型', name: 'ywlx', width: 50, align: 'left',
                    formatter: function (cellvalue, op, rows) {
                        if (rows.ywbz == 1) {
                            return $.enum.getDescByValue("EnumOutPatientType", cellvalue);
                        }
                        else {
                            return cellvalue;
                        }
                    }
                },
                { label: '出诊科室', name: 'czksmc', width: 80, align: 'left' },
                { label: '出诊医生', name: 'czysxm', width: 60, align: 'center' },
            ],
            pager: "#gridPager",
            sortname: 'czksmc,Period,queno asc',
            viewrecords: true,
            caption: "未分诊队列",
            autoScroll: false,//当autoScroll和shrinkToFit均为false时，会出现行滚动条
            shrinkToFit: false,//是否列宽度自适应。true=适应 false=不适应
        });
        $gridList.jqGrid('setFrozenColumns');//设置冻结列生效
        $("#time_horizon a.btn-default").click(function () {
            $("#time_horizon a.btn-default").removeClass("active");
            $(this).addClass("active");
            $('#btn_search').trigger("click");
        });



        $("#btn_search").click(function () {
            //var timeType = $("#time_horizon a.active").attr('data-value');
            //var dt = new Date().format("yyyy-MM-dd hh:mm:ss");
            //if (timeType != 1) {
            //    dt = $("#txt_jhrq").val();
            //}
            //var queryJson = {
            //    keyword: $("#txt_keyword").val(),
            //    qdsj:dt,

            //}

            var queryJson = getPostData();
            $gridList.jqGrid('setGridParam', {
                postData: queryJson,
                page: 1,
            }).trigger('reloadGrid');
            getNextCall();
        });
    }

    //回车事件
    $('#txt_keyword').keydownEnterEvent(function () {
        $('#btn_search').trigger('click');
    })

    function initControl() {
        $('#ks').ksFloatingSelector({
            itemdbclickhandler: function ($this) {
                $('#ks').attr('data-code', $this.attr('data-Code'))
                    .val($this.attr('data-Name'));
                $('#ksCode').attr('data-code', $this.attr('data-Code'))
                    .val($this.attr('data-Code'));
            },
        });
    }

    function jiaohao(mzh, calledstu) {
        $.ajax({
            type: "POST",
            url: "/QueueInfo/CallNumber",
            data: { mzh: mzh, calledstu: calledstu },
            dataType: "json",
            async: false,
            success: function (data) {
                $.modalAlert($.enum.getDescByValue("EmunQueueCalledStu", calledstu)+"完成！", 'success');
                $("#btn_search").trigger('click');
            }
        });
        if (calledstu == @((int)EmunQueueCalledStu.call )) {
            getNextCall(mzh);
        } else {
            getNextCall();
        }
    }

    function gridListcalled() {
        //var calledstu = $("#called_horizon a.active").attr('data-value');
        var $gridListcalled = $("#calledgridList");
        $gridListcalled.dataGrid({
            url: "/QueueManage/QueueInfo/GetQueueInfo",
            height: $(window).height() - 258,
            postData: { keyword: $("#txt_keyword").val(), qdsj: new Date().format('yyyy-MM-dd'), calledstu: $("#called_horizon a.active").attr('data-value')},
            colModel: [
                {
                    label: '操作区', name: 'action', width: 80, align: 'center', frozen: true, formatter: function (cellvalue, op, row) {
                        if ($("#time_horizon a.active").attr('data-value') != 1) {
                            return '';
                        }
                        else if (row.ispassed == "1" && $("#called_horizon a.active").attr('data-value') == '@((int)EmunQueueCalledStu.pass)') {//已过号
                            return '<input type="button" class="btn btn-default"  onclick="jiaohao(' + row.ywlsh + ',' + @Html.Raw(((int)EmunQueueCalledStu.call).ToString()) + ')" value="重新叫号" />';
                        }
                        else if (row.ispassed == "1" && $("#called_horizon a.active").attr('data-value') != '@((int)EmunQueueCalledStu.pass)') {//已过号,重新叫号过 显示在叫号队列
                            return '<input type="button" class="btn btn-default"  onclick="jiaohao(' + row.ywlsh + ',' + @Html.Raw(((int)EmunQueueCalledStu.call).ToString()) + ')" value="叫号" /> <input type="button" class="btn btn-default"  onclick="jiaohao(' + row.ywlsh + ',' + @Html.Raw(((int)EmunQueueCalledStu.pass).ToString()) + ')" value="过号" />';
                        }
                        else if (cellvalue == '@((int)EmunQueueCalledStu.reply)') {
                            return '<input type="button" class="btn btn-default"  onclick="jiaohao(' + row.ywlsh + ',' + @Html.Raw(((int)EmunQueueCalledStu.call).ToString()) + ')" value="呼叫" />';
                        }
                        else
                            return '';
                            //return '<input type="button" class="btn btn-default"  onclick="jiaohao(' + row.ywlsh + ',' + @Html.Raw(((int)EmunQueueCalledStu.call).ToString()) + ')" value="叫号" /> <input type="button" class="btn btn-default"  onclick="jiaohao(' + row.ywlsh + ',' + @Html.Raw(((int)EmunQueueCalledStu.pass).ToString()) + ')" value="过号" />';
                    },
                },
                { label: '序号', name: 'queno', width: 30, align: 'center', frozen: true },
                { label: '姓名', name: 'xm', width: 80, align: 'left', frozen: true },
                { label: '主键', name: 'Id', hidden: true },
                { label: 'ywbz', name: 'ywbz', hidden: true },
                {
                    label: '号源类型', name: 'ywlx', width: 50, align: 'left',
                    formatter: function (cellvalue, op, rows) {
                        if (rows.ywbz == 1) {
                            return $.enum.getDescByValue("EnumOutPatientType", cellvalue);
                        }
                        else {
                            return cellvalue;
                        }
                    }
                },
                { label: '出诊科室', name: 'czksmc', width: 80, align: 'left' },
                { label: '出诊医生', name: 'czysxm', width: 60, align: 'center' },
                {
                    label: '状态', name: 'calledstu', width: 50, align: 'center', formatter: function (cellvalue, op, row) {
                        if (cellvalue == '@((int)EmunQueueCalledStu.reply)') {
                            return "正在就诊";
                        }
                        else if (cellvalue != "") {
                            return $.enum.getDescByValue("EmunQueueCalledStu", cellvalue);
                        }
                        else {
                            return cellvalue;
                        }
                    }
                },
                { label: '叫号次数', name: 'calledtimes', width: 80, align: 'center' },
                //{ label: '年龄', name: 'nlshow', width: 50, align: 'left', },
                //{ label: '卡号', name: 'kh', width: 50, align: 'left', },
                //{ label: '病人性质', name: 'brxz', width: 50, align: 'left', },
                //{ label: '病人来源', name: 'brly', width: 50, align: 'left', },
                //{ label: '叫号次数', name: 'calledtimes', width: 50, align: 'left' },
                {
                    label: '是否过号', name: 'ispassed', width: 50, align: 'center', formatter: function (cellvalue, op, row) {
                        if (cellvalue == 1) {
                            return "是";
                        }
                        else {
                            return "否";
                        }
                    }
                },
                //{
                //    label: "允许登录", name: "Locked", width: 100, align: "center",
                //    formatter: function (cellvalue, options, rowObject) {
                //        if (cellvalue === true) {
                //            return '<span class=\"label label-default\">停用</span>';
                //        }
                //        else {
                //            return '<span class=\"label label-success\">正常</span>';
                //        }
                //    }
                //},
            ],
            pager: "#calledgridPager",
            sortname: 'czksmc,Period,queno asc',
            viewrecords: true,
            //caption: "分诊队列",
            autoScroll: false,//当autoScroll和shrinkToFit均为false时，会出现行滚动条
            shrinkToFit: false,//是否列宽度自适应。true=适应 false=不适应
        });
        $gridListcalled.jqGrid('setFrozenColumns');//设置冻结列生效
        //已叫队列
        $("#btn_call").click(function () {
            $("#btn_call").addClass("active");
            $("#btn_pass").removeClass("active");
            $("#btn_reply").removeClass("active");
            var queryJson = getPostData();
            queryJson.calledstu =@((int)EmunQueueCalledStu.call);
            $gridListcalled.jqGrid('setGridParam', {
                postData: queryJson,
                page: 1,
            }).trigger('reloadGrid');
        });
        //过号队列
        $("#btn_pass").click(function () {
            $("#btn_call").removeClass("active");
            $("#btn_pass").addClass("active");
            $("#btn_reply").removeClass("active");
            var queryJson = getPostData();
            queryJson.calledstu =@((int)EmunQueueCalledStu.pass);
            $gridListcalled.jqGrid('setGridParam', {
                postData: queryJson,
                page: 1,
            }).trigger('reloadGrid');
        });
        //到诊队列
        $("#btn_reply").click(function () {
            $("#btn_call").removeClass("active");
            $("#btn_pass").removeClass("active");
            $("#btn_reply").addClass("active");
            var queryJson = getPostData();
            queryJson.calledstu =@((int)EmunQueueCalledStu.reply);
            $gridListcalled.jqGrid('setGridParam', {
                postData: queryJson,
                page: 1,
            }).trigger('reloadGrid');
        });

        $("#btn_search").click(function () {
            var queryJson = getPostData();
            $gridListcalled.jqGrid('setGridParam', {
                postData: queryJson,
                page: 1,
            }).trigger('reloadGrid');
        });
    }

    function getPostData() {
        var timeType = $("#time_horizon a.active").attr('data-value');
        var dt = new Date().format("yyyy-MM-dd");
        if (timeType != 1) {
            dt = $("#txt_jhrq").val();
        }
        var queryJson = {
            keyword: $("#txt_keyword").val(),
            qdsj: dt,
            ks: $("#ksCode").val(),
            ywbz: $("#ywbz").val(),
            ywlx: $("#ywlx").val(),
        }
        return queryJson;
    }

    //function gridListcalledChange(calledstu) {
    //    var timeType = $("#time_horizon a.active").attr('data-value');
    //    var dt = new Date();
    //    if (timeType != 1) {
    //        dt = $("#txt_jhrq").val();
    //    }
    //    var queryJson = {
    //        keyword: $("#txt_keyword").val(),
    //        qdsj: dt,
    //        calledstu: calledstu
    //    }
    //    $gridListcalled.jqGrid('setGridParam', {
    //        postData: { queryJson: JSON.stringify(queryJson) },
    //        page: 1,
    //    }).trigger('reloadGrid');
    //}


    function getNextCall(mzh) {
        if ($("#time_horizon a.active").attr('data-value') != 1) {

            $("#sp_calling_no").html('');
            $("#sp_calling_xm").html('');
            $("#sp_calling_dept").html('');
            $("#sp_calling_doc").html('');

            $("#sp_nextcall_no").html('');
            $("#sp_nextcall_xm").html('');
            $("#sp_nextcall_dept").html('');
            $("#sp_nextcall_doc").html('');

            $("#sp_waiting_count").html('');
        } else {
            var postData = getPostData();
            postData.mzh = mzh;
            $.najax({
                type: "POST",
                url: "/QueueManage/QueueInfo/getNextCall",
                data: postData,
                dataType: "json",
                async: false,
                success: function (ajaxresp) {
                    var sp_calling_ywlx = $.enum.getDescByValue("EnumOutPatientType", ajaxresp.sp_calling_ywlx).replace("门诊", "");
                    var sp_nextcall_ywlx = $.enum.getDescByValue("EnumOutPatientType", ajaxresp.sp_nextcall_ywlx).replace("门诊","");
                    $("#sp_calling_no").html(ajaxresp.sp_calling_no == 0?"": ajaxresp.sp_calling_no);
                    $("#sp_calling_xm").html(ajaxresp.sp_calling_xm);
                    $("#sp_calling_dept").html(ajaxresp.sp_calling_dept);
                    $("#sp_calling_doc").html(ajaxresp.sp_calling_doc);
                    $("#sp_calling_ywlx").html(sp_calling_ywlx);

                    $("#sp_nextcall_no").html(ajaxresp.sp_nextcall_no);
                    $("#sp_nextcall_xm").html(ajaxresp.sp_nextcall_xm);
                    $("#sp_nextcall_dept").html(ajaxresp.sp_nextcall_dept);
                    $("#sp_nextcall_doc").html(ajaxresp.sp_nextcall_doc);
                    $("#sp_nextcall_ywlx").html(sp_nextcall_ywlx);
                    
                    $("#sp_waiting_count").html(ajaxresp.sp_waiting_count);
                }
            });
        }
    }
</script>